//
//  JieBanViewCell.m
//  TravelYo
//
//  Created by lanou3g on 15/10/30.
//  Copyright © 2015年 TravelYo. All rights reserved.
//

#import "JieBanViewCell.h"

@implementation JieBanViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
      
        
        [self addSubViews];
        
    }
    return self;
}


- (void)addSubViews
{
    UIView *backGroundView = [[UIView alloc] initWithFrame:CGRectMake(10, 0, kScreenWidth - 20, 175)];
    backGroundView.backgroundColor = [UIColor blueColor];
    backGroundView.alpha = 0.05;
    backGroundView.layer.cornerRadius = 10;
    backGroundView.layer.masksToBounds = YES;
    [self.contentView addSubview:backGroundView];
    
    // 时间
    self.timeLable = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, kScreenWidth / 2 - 15, 50)];
   // self.timeLable.backgroundColor = [UIColor purpleColor];
    [self.contentView addSubview:self.timeLable];
    
    // 城市
    self.citysLable = [[UILabel alloc] initWithFrame:CGRectMake(self.timeLable.right + 1, self.timeLable.top, kScreenWidth / 2 - 5, 60)];
    //self.citysLable.backgroundColor = [UIColor purpleColor];
    [self.contentView addSubview:self.citysLable];
    
    
    //标题
    self.titleLable = [[UILabel alloc] initWithFrame:CGRectMake(self.timeLable.left, self.timeLable.bottom + 10, kScreenWidth - 20, 60)];
   // self.titleLable.backgroundColor = [UIColor purpleColor];
    [self.contentView addSubview:self.titleLable];
    
    // 用户名
    self.usernameLable = [[UILabel alloc] initWithFrame:CGRectMake(self.titleLable.left, self.titleLable.bottom + 10, kScreenWidth / 3, 30)];
   // self.usernameLable.backgroundColor = [UIColor purpleColor];
    [self.contentView addSubview:self.usernameLable];
    
    // 多久以前
    self.publishTLable = [[UILabel alloc] initWithFrame:CGRectMake(self.usernameLable.right + 10, self.usernameLable.top, kScreenWidth / 4 + 10, 30)];
   // self.publishTLable.backgroundColor = [UIColor purpleColor];
    [self.contentView addSubview:self.publishTLable];
    
    // 评论
    self.replysLable = [[UILabel alloc] initWithFrame:CGRectMake(self.publishTLable.right + 10, self.publishTLable.top, kScreenWidth / 4 + 10, 30)];
   // self.replysLable.backgroundColor = [UIColor purpleColor];
    [self.contentView addSubview:self.replysLable];
    
}


// 重写model方法
- (void)setJBModel:(JieBanModel *)jBModel
{
    // 时间
    NSDate *data = [NSDate dateWithTimeIntervalSince1970:jBModel.start_time];
    NSDateFormatter *fomatter = [[NSDateFormatter alloc] init];
    [fomatter setDateFormat:@"YY.MM.dd"];
    NSString *showtime = [fomatter stringFromDate:data];
    
    NSDate *data1 = [NSDate dateWithTimeIntervalSince1970:jBModel.end_time];
    NSDateFormatter *fomatter1 = [[NSDateFormatter alloc] init];
    [fomatter1 setDateFormat:@"YY.MM.dd"];
    NSString *showtime1 = [fomatter stringFromDate:data1];
    
    self.timeLable.text = [NSString stringWithFormat:@"%@-%@", showtime, showtime1];
    self.timeLable.font = [UIFont systemFontOfSize:20];
    self.timeLable.alpha = 0.8;
                    
    //  城市
    self.citysLable.text = jBModel.citys_str;
    self.citysLable.numberOfLines = 0;
    self.citysLable.alpha = 0.8;
   
    // 标题
    self.titleLable.text = jBModel.title;
    self.titleLable.alpha = 0.8;
    self.titleLable.numberOfLines = 0;
    // 用户名
   self.usernameLable.text = jBModel.username;
    self.usernameLable.alpha = 0.6;
    // 多久前
    NSDate *nowDate = [NSDate date];
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:jBModel.publish_time];
    NSTimeInterval subTimeInteval = [nowDate timeIntervalSinceDate:date];
    if (subTimeInteval < 60) {
        self.publishTLable.text = @"刚刚";
        self.publishTLable.alpha = 0.6;
        
    } else if (subTimeInteval >= 60 && subTimeInteval < 3600) {
        self.publishTLable.text = [NSString stringWithFormat:@"%d分钟前",(int)subTimeInteval / 60];
        self.publishTLable.alpha = 0.6;
    } else if (subTimeInteval >= 3600 && subTimeInteval < 24 * 3600) {
        self.publishTLable.text = [NSString stringWithFormat:@"%d小时前",(int)subTimeInteval / 3600];
        self.publishTLable.alpha = 0.6;
    }
    
    
    
    
    // 评论
    self.replysLable.text = [NSString stringWithFormat:@"评论:%ld", jBModel.replys];
    self.replysLable.alpha = 0.6;
}






- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
